<template>
  <el-container>
    <el-main>
      <div class="studentList-info-title">
        <p>咨询预约管理
          <!-- <el-button @click="showaddUser()" class="addUserBtn">添加咨询师</el-button> -->
        </p>
      </div>
      <!-- <div class="filter-container" style="margin-top: 20px;padding: 10px;">
          <el-form :model="listQuery.condition" class="demo-infoForm" size="mini" label-position="right" :inline="true">
            <el-form-item label="名称：">
              <el-input v-model="listQuery.condition.memberName" class="com_input" clearable></el-input>
            </el-form-item>
            <el-button type="primary" @click="onSubmit" size="mini"
              style="background-color: #409EFF;border-color: #409EFF;" icon="el-icon-search" :loading="loading">搜索
            </el-button>
            <el-button type="primary" @click="onReload" size="mini"
              style="background-color: #409EFF;border-color: #409EFF;" icon="el-icon-refresh">刷新</el-button>
          </el-form>
        </div> -->
      <div class="studentList-info-body">
        <div class="studentList">
          <el-table fixed :data="list" stripe style="width: 100%" max-height="500">
            <el-table-column type="index" :index="typeIndex" label="序号" align="center"></el-table-column>
            <el-table-column prop="username" label="老师姓名" align="center"></el-table-column>
            <el-table-column prop="stuName" label="学生姓名" align="center"></el-table-column>
            <el-table-column align="center" label="操作" fixed="right" width="200">
              <template slot-scope="scope">
                <el-button size="mini" type="primary" plain @click="modifyUser(scope.$index, scope.row)"
                  style="background-color: #409EFF;border-color: #409EFF;color:#fff;">录入系统</el-button>
                <!-- <el-button size="mini" type="primary" plain @click="deleteUser(scope.$index, scope.row)"
                  style="background-color: #409EFF;border-color: #409EFF;color:#fff;">删除</el-button> -->
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="studentList-pagination">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="listQuery.current" :page-sizes="[10,20,30,50]" :page-size="listQuery.limit"
            :layout="paginationData" :total="total">
          </el-pagination>
        </div>
      </div>
      <div>
        <el-dialog :visible.sync="userDialogVisible" title="添加咨询师" @close="closepage" width="650px"
          :close-on-click-modal="false" center>
          <div class='shop-frame'>
            <el-form autoComplete="on" :model="conRecordForm" :rules="userRules" ref="conRecordForm" label-width="120px"
              label-position="right" class="card-box shop-form">
              <el-form-item class="inp" prop="date" label="时间：" style="width: 80%;">
                <el-date-picker v-model="conRecordForm.date" type="datetime" placeholder="选择日期时间">
                </el-date-picker>
              </el-form-item>
              <el-form-item class="inp" prop="site" label="地点：" style="width: 80%;">
                <el-input name='site' v-model="conRecordForm.site" autoComplete="on" clearable />
              </el-form-item>
              <div class="studentList-btn">
                <el-button class="formBtn" :loading="loading" @click="handleComplaint()">
                  提交
                </el-button>
                <el-button class="formBtn" :loading="loading" @click="handleCancel()">
                  取消
                </el-button>
              </div>
            </el-form>
          </div>
        </el-dialog>
      </div>
    </el-main>
  </el-container>
</template>
<script>
  import {
    addConrecord
  } from '@/api/conrecord'
  import {
    getConsultantPage,
    addConsultant,
    updateConsultant
  } from '@/api/consultant'
  import {
    getAppointmentPage,
    addAppointment,
    updateAppointment
  } from '@/api/appointment'
  // import {sendMessage } from '@/api/message'
  export default {
    data() {
      return {
        conRecordForm: {},
        messageDialogVisible: false,
        messageForm: {
          userName: '',
          userId: '',
          messageType: '0',
          messageContent: ''
        },
        userRules: {
          name: [{
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }],
          password: [{
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }],
          phone: [{
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }]
        },
        addFlag: true,
        userDialogVisible: false,
        userForm: {
          name: '',
          password: '',
          phone: '',
          id: ''
        },
        loading: false,
        list: [],
        listQuery: {
          current: 1,
          size: 10,
          condition: {}
        },
        paginationData: 'total, sizes, prev, pager, next, jumper',
        total: null,
        listLoading: false,
        exportDialogVisible: false,
        exportloading: false,
        exportFile: {
          text: ''
        },
        exportForm: {
          file: ''
        }
      }
    },
    methods: {
      // sendMessage(index, row) {
      //   this.messageDialogVisible = true
      //   this.messageForm.userId = row.id
      //   this.messageForm.userName = row.name
      // },
      // handleSubmit() {
      //   sendMessage(this.messageForm).then(resp => {
      //     if (resp.code == 200) {
      //       this.$message({
      //         type: 'success',
      //         message: "添加成功"
      //       })
      //       this.loading = false
      //       this.getData()
      //       this.messageDialogVisible = false
      //       this.$nextTick(() => {
      //         this.$refs['userForm'].resetFields()
      //       })
      //     } else {
      //       this.loading = false
      //       this.$message({
      //         type: 'error',
      //         message: resp.data
      //       })
      //     }
      //   })
      // },
      modifyUser(index, row) {
        this.userForm = row
        this.addFlag = false
        this.conRecordForm.appId = row.id
        this.userDialogVisible = true
      },
      showaddUser() {
        this.addFlag = true
        this.userDialogVisible = true
      },
      closepage() {
        this.$nextTick(() => {
          this.$refs['userForm'].resetFields()
        })
      },
      handleComplaint() {
        addConrecord(this.conRecordForm).then(resp => {
          if (resp.code == 200) {
            this.$message({
              type: 'success',
              message: "添加成功"
            })
            this.loading = false
            this.getData()
            this.userDialogVisible = false
            this.$nextTick(() => {
              this.$refs['userForm'].resetFields()
            })
          } else {
            this.loading = false
            this.$message({
              type: 'error',
              message: resp.data
            })
          }
        })
        // this.$refs.userForm.validate(vail => {
        //   if (vail) {
        //     this.loading = true
        //     if (this.addFlag) {
        //       addConrecord(this.conRecordForm).then(resp => {
        //         if (resp.code == 200) {
        //           this.$message({
        //             type: 'success',
        //             message: "添加成功"
        //           })
        //           this.loading = false
        //           this.getData()
        //           this.userDialogVisible = false
        //           this.$nextTick(() => {
        //             this.$refs['userForm'].resetFields()
        //           })
        //         } else {
        //           this.loading = false
        //           this.$message({
        //             type: 'error',
        //             message: resp.data
        //           })
        //         }
        //       })
        //     } else {
        //       updateConsultant(this.userForm).then(resp => {
        //         if (resp.code == 200) {
        //           this.$message({
        //             type: 'success',
        //             message: "修改成功"
        //           })
        //           this.loading = false
        //           this.getData()
        //           this.userDialogVisible = false
        //           this.$nextTick(() => {
        //             this.$refs['userForm'].resetFields()
        //           })
        //         } else {
        //           this.loading = false
        //           this.$message({
        //             type: 'error',
        //             message: resp.data
        //           })
        //         }
        //       })
        //     }
        //   } else {
        //     return false
        //   }
        // })
      },
      handleCancel() {
        this.$nextTick(() => {
          this.$refs['userForm'].resetFields()
        })
        this.userDialogVisible = false
      },
      onReload() {
        this.listQuery.condition = {}
        this.getData()
      },
      onSubmit() {
        this.loading = true
        this.listQuery.current = 1
        this.getData()
        this.loading = false
      },
      getData() {
        getAppointmentPage(this.listQuery).then(resp => {
          if (resp.code == 200) {
            this.list = resp.data.records
            this.total = parseInt(resp.data.total)
            this.listLoading = false
          }
        })
      },
      typeIndex(index) {
        return index + (this.listQuery.current - 1) * this.listQuery.size + 1
      },
      handleSizeChange(val) {
        this.listQuery.size = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.listQuery.current = val
        this.getData()
      },
      deleteUser(index, row) {
        this.$confirm('删除后不可恢复，确定删除？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteUser({
            'id': row.id
          }).then(resp => {
            if (resp.code == 200) {
              this.$message({
                type: 'success',
                message: "删除成功！"
              })
              this.getData()
            } else {
              this.$message({
                type: 'error',
                message: "系统错误！"
              })
            }
          })
        })
      }
    },
    created() {
      this.getData()
    }
  }

</script>
<style>
  .studentList-info-container {
    /* width: 1200px; */
    min-height: 905px;
    background-color: #ffffff;
    margin: 0 auto;
  }

  .studentList-info-title {
    width: auto;
    height: 56px;
    background-color: #EDEFF2;
    font-size: 22px;
    /* font-family: SimHei; */
    font-weight: 400;
    color: #333333;
    line-height: 48px;
    border-left: 6px solid #409EFF;
    text-align: left;
  }

  .studentList-info-title p {
    padding-left: 25px;
    padding-top: 5px;
  }

  .addUserBtn {
    width: 140px;
    height: 44px;
    color: #ffffff;
    background-color: #409EFF;
    float: right;
    margin-right: 70px;
  }

  .studentList-btn {
    text-align: center;
  }

  .studentList-btn .formBtn {
    width: 120px;
    height: 44px;
    background-color: #409EFF;
    border-color: #409EFF;
    color: #ffffff;
  }

  .studentList-pagination {
    margin-top: 50px;
    text-align: center;
    padding-bottom: 50px;
  }

  .el-pagination.is-background .el-pager li.active {
    background-color: #409EFF;
  }

</style>
